{include file="public/header" /}
<style>
    /*缩略图高度*/
    .layui-table-cell {height: 36px;}
</style>
<body class="gray-bg">
<div class="wrapper wrapper-content">
    <div class="ibox float-e-margins">
        <div class="ibox-content">
            <div class="row">
                <!--搜索框开始-->
                <div class="col-sm-12">
                    <div class="layui-form layui-form-item">

                        <div class="layui-col-md6 layui-input-inline" style="margin-top: 10px">
                            <input type="text" id="class_title" class="layui-input search" name="class_title" placeholder="课程标题"/>
                        </div>

                        <div class="layui-input-inline" style="margin-top: 10px">
                            <select name="class_cate_id" lay-search="" class="layui-input search" id="class_cate_id"  lay-filter="class_cate_id">
                                <option value="">---- 请选择分类 ----</option>
                                {foreach name="cate" item="vo"}
                                <option value="{$vo.c_cate_id}" >{$vo.c_cate_name}</option>
                                {/foreach}
                            </select>
                        </div>

                        <div class="layui-input-inline layui-form" style="margin-top: 10px">
                            <select name="class_type" id="class_type" lay-search="" class="layui-input">
                                <option value="">不限类型</option>
                                <option value="1">免费</option>
                                <option value="2">付费</option>
                                <option value="3">兑换码</option>
                            </select>
                        </div>

                        <div class="layui-input-inline layui-form" style="margin-top: 10px">
                            <select name="class_is_recommend" id="class_is_recommend" lay-search="" class="layui-input">
                                <option value="">不限推荐类型</option>
                                <option value="1">推荐</option>
                                <option value="2">不推荐</option>
                            </select>
                        </div>

                        <div class="layui-input-inline layui-form" style="margin-top: 10px">
                            <select name="class_is_hot" id="class_is_hot" lay-search="" class="layui-input">
                                <option value="">不限热门类型</option>
                                <option value="1">热门</option>
                                <option value="2">非热门</option>
                            </select>
                        </div>

                        <div class="layui-input-inline layui-form" style="margin-top: 10px">
                            <select name="class_video_audio" id="class_video_audio" lay-search="" class="layui-input">
                                <option value="">不限课程形式</option>
                                <option value="1">视频</option>
                                <option value="2">音频</option>
                            </select>
                        </div>

                        <div class="layui-input-inline layui-form" style="margin-top: 10px">
                            <select name="class_status" id="class_status" lay-search="" class="layui-input">
                                <option value="">不限状态</option>
                                <option value="1">上架中</option>
                                <option value="2">已下架</option>
                            </select>
                        </div>

                        <div class="layui-input-inline" style="margin-top: 10px">
                            <button class="layui-btn" lay-submit="" lay-filter="LAY-search">立即搜索</button>
                            <button class="layui-btn layui-btn-normal" id="empty" lay-submit="" lay-filter="LAY-search">
                                重置
                            </button>
                        </div>
                    </div>
                </div>
                <!--搜索框结束-->
                <!--操作框开始-->
                <div class="col-sm-12">
                    <div class="input-group">
                        <button class="btn btn-primary" type="button" onclick="wk.href('{:url('classAdd')}');">
                            <i class="fa fa-plus"></i> 添加课程
                        </button>

                    </div>
                </div>
                <!--操作框结束-->
            </div>
            <div class="hr-line-dashed"></div>

            <div class="example-wrap">
                <div class="example">
                    <table class="layui-hide" id="test" lay-filter="testReload"></table>

                    <!--状态显示模板-->
                    <script type="text/html" id="classStatus">
                        {{# if(d.class_status == 1){ }}
                        上架中
                        {{# } }}
                        {{# if(d.class_status == 2){ }}
                        已下架
                        {{# } }}
                    </script>

                    <script type="text/html" id="classType">
                        {{# if(d.class_type == 1){ }}
                        免费
                        {{# } }}
                        {{# if(d.class_type == 2){ }}
                        付费
                        {{# } }}
                        {{# if(d.class_type == 3){ }}
                        兑换码
                        {{# } }}
                    </script>

                    <script type="text/html" id="classIsRecommend">
                        {{# if(d.class_is_recommend == 1){ }}
                        推荐
                        {{# } }}
                        {{# if(d.class_is_recommend == 2){ }}
                        不推荐
                        {{# } }}
                    </script>

                    <script type="text/html" id="classIsHot">
                        {{# if(d.class_is_hot == 1){ }}
                        热门
                        {{# } }}
                        {{# if(d.class_is_hot == 2){ }}
                        非热门
                        {{# } }}
                    </script>

                    <script type="text/html" id="classVideoAudio">
                        {{# if(d.class_video_audio == 1){ }}
                        视频
                        {{# } }}
                        {{# if(d.class_video_audio == 2){ }}
                        音频
                        {{# } }}
                    </script>

                    <!--图片模板-->
                    <script type="text/html" id="imgTpl">
                        <img src="{{d.class_thumb}}" class="img-circle table-img" onerror="this.src='/static/admin/images/head_default.gif'"  />
                    </script>

                    <!--操作模板-->
                    <script type="text/html" id="opeBar">
                        <a href="javascript:;" onclick="wk.layer_show('查看详情', '{:url('classDetail')}?class_id={{d.class_id}}')" class="btn btn-warning btn-xs m-r-xs" title="详情">详情</a>
                        <a href="javascript:;" onclick="wk.href('{:url('classEdit')}?class_id={{d.class_id}}')" class="btn btn-primary btn-xs m-r-xs" title="编辑">编辑</a>
                        {{# if(d.class_status == 1){ }}
                        <a href="javascript:;" onclick="wk.confirm('{{d.class_id}}','{:url('classDown')}', '确定下架？')" class="btn btn-warning btn-xs m-r-xs" title="下架">下架</a>
                        {{# } }}
                        {{# if(d.class_status == 2) { }}
                        <a href="javascript:;" onclick="wk.confirm('{{d.class_id}}','{:url('classOn')}', '确定上架？')" class="btn btn-info btn-xs m-r-xs" title="上架">上架</a>
                        {{# } }}
                        {{# if(d.class_is_recommend == 1){ }}
                        <a href="javascript:;" onclick="wk.confirm('{{d.class_id}}','{:url('classUnrecommend')}', '确定取消推荐？')" class="btn btn-warning btn-xs m-r-xs" title="取消推荐">取消推荐</a>
                        {{# }else{ }}
                        <a href="javascript:;" onclick="wk.confirm('{{d.class_id}}','{:url('classRecommend')}', '确定设置推荐？')" class="btn btn-info btn-xs m-r-xs" title="设为推荐">设为推荐</a>
                        {{# } }}
                        {{# if(d.class_is_hot == 1){ }}
                        <a href="javascript:;" onclick="wk.confirm('{{d.class_id}}','{:url('classUnhot')}', '确定取消热门？')" class="btn btn-warning btn-xs m-r-xs" title="取消热门">取消热门</a>
                        {{# }else{ }}
                        <a href="javascript:;" onclick="wk.confirm('{{d.class_id}}','{:url('classHot')}', '确定设置热门？')" class="btn btn-info btn-xs m-r-xs" title="设为热门">设为热门</a>
                        {{# } }}
                        <a href="javascript:;" onclick="wk.layer_show('章节','{:url('classSection')}?class_id={{d.class_id}}')" class="btn btn-warning btn-xs m-r-xs" title="章节">章节</a>
                        <a href="javascript:;" onclick="wk.layer_show('评价','{:url('classCommentList')}?class_id={{d.class_id}}')" class="btn btn-warning btn-xs m-r-xs" title="评价">评价</a>
                        <a href="javascript:;" onclick="wk.confirm('{{d.class_id}}','{:url('classDel')}')" class="btn btn-danger btn-xs m-r-xs" title="删除">删除</a>
                    </script>
                </div>
            </div>
        </div>
    </div>
</div>
<textarea id="allidsForOut" class="hidden"></textarea>
{include file="public/footer" /}
<script>
    //layui渲染数据表格
    layui.use('table', function () {
        var table = layui.table
                , form = layui.form;
        table.render({
            elem: '#test'
            , url: '{:url("Classes/index")}'
            , response: {
                statusCode: 220 //成功的状态码，默认：0
            }
            , page: true
//            , size: 'lg' //sm小尺寸的表格 lg大尺寸
            , cellMinWidth: 150
            , limits: [5, 10, 15, 20, 25, 30]
            , limit: "{:config('pages')}"
            , loading: true
            , id: 'testReload'
            , cols: [[
//                {type: 'checkbox', fixed: 'left',}
                  {field: 'class_id', width: 60, title: 'ID', align: 'center'}
                , {field: 'class_title', width: '', title: '课程标题', align: 'center'}
                , {field: 'class_thumb', width: 70, title: '主图', align: 'center', templet: '#imgTpl'}
                , {field: 'c_cate_name', width: 100, title: '分类', align: 'center'}
                , {field: 'class_type', width: 90, title: '类型', align: 'center', toolbar: '#classType'}
                , {field: 'class_price', width: 90, title: '价格', align: 'center'}
                , {field: 'class_status', width: 80, title: '状态', align: 'center', toolbar: '#classStatus'}
                , {field: 'class_is_recommend', width: 90, title: '是否推荐', align: 'center', toolbar: '#classIsRecommend'}
                , {field: 'class_is_hot', width: 90, title: '是否热门', align: 'center', toolbar: '#classIsHot'}
                , {field: 'class_video_audio', width: 90, title: '课程形式', align: 'center', toolbar: '#classVideoAudio'}
                , {field: 'class_apply_number', width: 90, title: '报名人数', align: 'center'}
                , {field: 'class_section_number', width: 80, title: '章节数', align: 'center'}
                , {field: 'class_create_time', width: 160, title: '创建时间', align: 'center'}
                , {field: 'class_update_time', width: 160, title: '编辑时间', align: 'center'}
                , {fixed: 'right', width: 440, title: '操作', align: 'center', toolbar: '#opeBar'}
            ]]
            , done: function (res, curr, count) {
                $('.img-circle').viewer({
                    url: 'data-original',
                });
            }
        });
        $('.layuiBtn').on('click', function () {
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });
        var getIds = function () {
            var ids = [];
            var checkStatus = table.checkStatus('testReload')
                    , data = checkStatus.data;
            $.each(data, function (index, item) {
                ids.push(item['class_id'])
            });
            return ids;
        }
    });
</script>
</body>
</html>